package com.dddframework.data.typehandlers;

import com.dddframework.core.utils.JsonKit;
import com.dddframework.data.typehandlers.type.IntegerList;
import lombok.extern.slf4j.Slf4j;

/**
 * 类型转换：Varchar <-> IntegerList，使用JsonArray存储
 *
 * @author Jensen
 * @公众号 架构师修行录
 * @date 2021/9/12 14:52
 * @since jdk1.8
 */
@Slf4j(topic = "### BASE-DATA : TypeHandlers ###")
public class IntegerListTypeHandler extends BaseStringTypeHandler<IntegerList> {
    public IntegerListTypeHandler() {
        log.debug("Loading IntegerListTypeHandler, type: IntegerList");
    }

    @Override
    protected String convert(IntegerList obj) {
        return JsonKit.toJson(obj);
    }

    @Override
    protected IntegerList parse(String result) {
        return IntegerList.convert(JsonKit.toList(result, Integer.class));
    }
}
